#!/usr/bin/python

##################
# prevviewer.py
#
# Copyright David Baddeley, 2009
# d.baddeley@auckland.ac.nz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##################

#!/usr/bin/env python
# generated by wxGlade 0.3.3 on Mon Jun 14 06:48:07 2004

import wx

#import viewpanel
import PYME.cSMI as example

from PYME.DSView.viewpanellite import MyViewPanel

class PrevViewFrame(wx.Frame):
	def __init__(self, parent, title, dstack):
		wx.Frame.__init__(self,parent, -1, title)

		self.ds = dstack
		self.vp = MyViewPanel(self, self.ds)
		sizer = wx.BoxSizer(wx.VERTICAL)
		sizer.Add(self.vp, 1,wx.EXPAND,0)
		self.SetAutoLayout(1)
		self.SetSizer(sizer)
		sizer.Fit(self)
		#sizer.SetSizeHints(self)

		# Menu Bar
		self.menubar = wx.MenuBar()
		self.SetMenuBar(self.menubar)
		tmp_menu = wx.Menu()
		#F_SAVE = wx.NewId()
		#F_CLOSE = wx.NewId()
		tmp_menu.Append(wx.ID_SAVEAS, "Save As", "", wx.ITEM_NORMAL)
		tmp_menu.Append(wx.ID_CLOSE, "Close", "", wx.ITEM_NORMAL)
		self.menubar.Append(tmp_menu, "File")
		# Menu Bar end

		wx.EVT_MENU(self, wx.ID_SAVEAS, self.saveStack)
		wx.EVT_MENU(self, wx.ID_CLOSE, self.menuClose)

		self.statusbar = self.CreateStatusBar(1, wx.ST_SIZEGRIP)

		self.Layout()
		self.update()

	def update(self):
		self.vp.imagepanel.Refresh()
		if ('genStatusText' in dir(self)):
			self.statusbar.SetStatusText(self.genStatusText())
		else:
			self.SetStatusText('')

	def saveStack(self, event=None):
		fdialog = wx.FileDialog(None, 'Save Data Stack as ...',
			wildcard='*.kdf', style=wx.SAVE|wx.HIDE_READONLY)
		succ = fdialog.ShowModal()
		if (succ == wx.ID_OK):
			self.ds.SaveToFile(fdialog.GetPath())
			self.SetTitle(fdialog.GetFilename())
			self.saved = True

	def menuClose(self, event):
		self.Close()

